<template>
  <div class="ArtistWork">
    <dv-border-box-8 style="padding-top: 15px">
      <dv-decoration-7 style="width: 100%; height: 30px"
        >艺术家作品数量排名（前五）</dv-decoration-7
      >
      <dv-capsule-chart :config="config" style="width: 100%; height: 350px" />
    </dv-border-box-8>
  </div>
</template>

<script>
import { getMaterialstatistic } from "@/api/visualization.js";

export default {
  name: "ArtistWork",
  data() {
    return {
      config: {
        data: [{ name: "", value: "" }],
        colors: ["#37A2DA", "#32C5E9", "#67E0E3", "#64FEDA", "#68F0AE"],
        unit: "件/单位",
        showValue: true,
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      getMaterialstatistic()
        .then((res) => {
          console.log("API 返回的数据：", res);
          if (res && res.data) {
            this.config = {
              ...this.config,
              data: res.data.map((item) => ({
                name: item.real_name,
                value: item.artwork_count,
              })),
            };
            console.log("转换后的数据：", this.config.data);
          } else {
            console.error("数据格式不正确：", res);
          }
        })
        .catch((err) => {
          console.error("数据获取失败：", err);
        });
    },
  },
};
</script>

<style lang="less" scoped></style>
